from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def play_only_1(self):
        return True

    def get_name(self):
        return "大圣顶住"

    def game_alert(self):
        self.alert_close_by_file("./game/img/大圣顶住")

    def check_done(self, throw=True):
        return False

    def handle_main(self):
        self.d.sleep(5)
        while self.img_exit("./game/img/大圣顶住/game_start_main.png", 3):
            self.log_msg("等待进入游戏")
            self.d.sleep(5)
        self.log_msg("已进入游戏")

        while True:
            self.log_msg("等待进入游戏主界面")
            if self.img_exit('./game/img/大圣顶住/game_main.png', 3):
                break
            self.game_alert()
        self.log_msg("已进入游戏主界面")

        if self.img_exit('./game/img/大圣顶住/prize.png', 2):
            self.log_msg("开始领挂机奖励")
            self.img_click_if_exists("点击奖励已满图标", './game/img/大圣顶住/prize.png', './game/img/大圣顶住/prize_01.png')
            self.log_msg("点击领取")
            self.img_click('./game/img/大圣顶住/prize_01.png')
            if self.img_exit('./game/img/大圣顶住/prize_alert.png', 2):
                self.log_msg("存在确认弹窗")
                self.img_click('./game/img/大圣顶住/prize_alert_1.png')
            self.click_bottom()

        self.img_click_if_exists("点击宝箱", './game/img/大圣顶住/box.png', './game/img/大圣顶住/box_01.png')
        for i in range(2):
            self.log_msg("点击开10个宝箱")
            self.img_click('./game/img/大圣顶住/box_01.png')
            self.d.sleep(2)
            self.click_top()
            self.click_top()

        self.log_msg("开20个宝箱完成，点击返回战斗界面")
        self.img_click('./game/img/大圣顶住/play.png')
        for i in range(2):
            self.game_alert()
            self.d.sleep(5)

        return True
